const Path = require('path');
const Webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

const exportLess = {
    test: /\.less$/,
    use: ExtractTextPlugin.extract({
        fallback: {
            loader: 'style-loader',
            options: {
                singleton: true
            }
        },
        use: [{
            loader: 'css-loader',
            options: {
                minimize: true
            }
        }, {
            loader: 'less-loader'
        }]
    })
}

const exportImage = {
    test: /\.(jpg|jpeg|png|gif)$/,
    use: {
        loader: 'url-loader',
        options: {
            name: '[name].[ext]',
            outputPath: 'images/',
            limit: 2000
        }
    }
}

const exportHtml = {
    test: /\.html$/,
    use: {
        loader: 'html-loader',
        options: {
            attrs: ['img:src']
        }
    }
}

const WebpackConfig = {
    entry: {
        app: './src/scripts/app.js'
    },
    output: {
        path: Path.resolve(__dirname, './dist'),
        publicPath: './dist/',
        filename: '[name].bundle.js',
    },
    module: {
        rules: [exportLess, exportImage, exportHtml]
    },
    plugins: [
        new ExtractTextPlugin({
            filename: '[name].min.css',
            allChunks: true
        })
    ]
};

module.exports = WebpackConfig;